package com.zx.notification.common.param;

import com.zx.validation.annotation.ParameterValidation;
import com.zx.validation.enums.DateTimeFormatEnum;
import com.zx.validation.enums.ValidateRulesEnum;
import com.zx.validation.groups.Create;
import com.zx.validation.groups.Query;
import com.zx.validation.groups.StatusUpdate;
import com.zx.validation.groups.Update;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Set;

/**
 * <p>
 * description: 通知渠道配置参数 <br>
 * create: 2025-10-15
 * </p>
 *
 * @author zhou  xun
 */
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class NotificationChannelsConfigParam implements Serializable, Create, Update, Query, StatusUpdate {
    /**
     * 配置ID
     */
    @ParameterValidation(index = 0, desc = "配置ID", rules = {ValidateRulesEnum.NOT_NULL})
    private String id;

    /**
     * 渠道类型: INBOX,WEBSOCKET,SMS,EMAIL,APP_PUSH,WECHAT
     */
    @ParameterValidation(index = 0, desc = "渠道类型", rules = {ValidateRulesEnum.NOT_NULL})
    private String channelType;

    /**
     * 渠道名称
     */
    @ParameterValidation(index = 0, desc = "渠道名称", rules = {ValidateRulesEnum.NOT_NULL})
    private String channelName;

    /**
     * 消息队列类型: RABBITMQ,ROCKETMQ,ACTIVEMQ,KAFKA
     */
    @ParameterValidation(index = 0, desc = "MQ类型", rules = {ValidateRulesEnum.NOT_NULL})
    private String mqType;

    /**
     * 队列名称
     */
    @ParameterValidation(index = 0, desc = "队列名称", rules = {ValidateRulesEnum.NOT_NULL})
    private String queueName;

    /**
     * 队列目标类型: QUEUE,TOPIC - 当模板消费模式为QUEUE时使用此配置
     */
    @ParameterValidation(index = 0, desc = "队列目标类型", rules = {ValidateRulesEnum.NOT_NULL})
    private String queueDestinationType;

    /**
     * 队列路由键: RabbitMQ专用，用于点对点模式的消息路由
     */
    private String queueRoutingKey;

    /**
     * 队列标签: RocketMQ专用，用于点对点模式的消息过滤
     */
    private String queueTag;

    /**
     * 主题名称
     */
    @ParameterValidation(index = 0, desc = "主题名称", rules = {ValidateRulesEnum.NOT_NULL})
    private String topicName;

    /**
     * 主题目标类型: QUEUE,TOPIC - 当模板消费模式为TOPIC时使用此配置
     */
    @ParameterValidation(index = 0, desc = "主题目标类型", rules = {ValidateRulesEnum.NOT_NULL})
    private String topicDestinationType;

    /**
     * 主题路由键: RabbitMQ专用，用于广播模式的消息路由
     */
    private String topicRoutingKey;

    /**
     * 主题标签: RocketMQ专用，用于广播模式的消息过滤
     */
    private String topicTag;

    /**
     * WebSocket端点地址
     */
    private String websocketEndpoint;

    /**
     * WebSocket路径
     */
    private String websocketPath;

    /**
     * 推送策略: REQUIRED,OPTIONAL,FALLBACK
     */
    @ParameterValidation(index = 0, desc = "推送策略", rules = {ValidateRulesEnum.NOT_NULL})
    private String pushStrategy;

    /**
     * 最大重试次数
     */
    @ParameterValidation(index = 0, desc = "最大重试次数", rules = {ValidateRulesEnum.NOT_NULL})
    private Integer maxRetryCount;

    /**
     * 状态: 0-停用 1-启用
     */
    @ParameterValidation(index = 0, desc = "状态", rules = {ValidateRulesEnum.NOT_NULL})
    private Integer status;

    /**
     * 创建者
     */
    private String createBy;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新者
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 备注
     */
    private String remark;

    /**
     * 当前页码
     */
    @ParameterValidation(index = 0, desc = "当前页码", rules = {ValidateRulesEnum.NUMBER_MIN}, numberMin = 1)
    private Long pageNum;

    /**
     * 每页条数
     */
    @ParameterValidation(index = 0, desc = "每页条数", rules = {ValidateRulesEnum.NUMBER_MIN, ValidateRulesEnum.NUMBER_MAX}, numberMin = 1, numberMax = 1000)
    private Long pageSize;

    /**
     * 创建时间开始
     * 用于时间范围查询，查询大于等于该时间的记录
     */
    @ParameterValidation(index = 0, desc = "创建时间开始", rules = {ValidateRulesEnum.NULL_DATE_TIME}, dateFormat = DateTimeFormatEnum.DATE_TIME)
    private LocalDateTime createTimeStart;

    /**
     * 创建时间结束
     * 用于时间范围查询，查询小于等于该时间的记录
     */
    @ParameterValidation(index = 0, desc = "创建时间结束", rules = {ValidateRulesEnum.NULL_DATE_TIME}, dateFormat = DateTimeFormatEnum.DATE_TIME)
    private LocalDateTime createTimeEnd;

    @Override
    public Set<String> getCreateGroupFields() {
        return Set.of("channelType", "channelName", "mqType", "queueName", "queueDestinationType",
                "topicName", "topicDestinationType", "pushStrategy", "maxRetryCount", "status", "remark");
    }

    @Override
    public Set<String> getUpdateGroupFields() {
        return Set.of("id", "channelType", "channelName", "mqType", "queueName", "queueDestinationType",
                "queueRoutingKey", "queueTag", "topicName", "topicDestinationType", "topicRoutingKey",
                "topicTag", "websocketEndpoint", "websocketPath", "pushStrategy", "maxRetryCount", "remark");
    }

    @Override
    public Set<String> getQueryGroupFields() {
        return Set.of("channelType", "channelName", "mqType", "status", "pageNum", "pageSize",
                "createTimeStart", "createTimeEnd");
    }

    @Override
    public Set<String> getStatusUpdateGroupFields() {
        return Set.of("id", "status");
    }
}